<title>业绩统计</title>
<!--当前位置开始-->
<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <script type="text/html" template lay-done="layui.data.updateMainBreadcrumb();">
        </script>
    </div>
</div>
<script type="text/html" template lay-type="Post" lay-url="{{ layui.setter.apiUrl }}Api/CoreCmsUser/GetIndex" lay-done="layui.data.done(d);">
</script>
<!--当前位置结束-->
<style>
    /* 重写样式 */
</style>
<script type="text/html" id="LAY-app-Goods-toolbar">
    <div class="layui-form coreshop-toolbar-search-form">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">时间范围：</label>
                <div class="layui-input-inline layui-inline-6">
                    <input type="text" name="date" value="" id="date" placeholder="请输入起止时间" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline" style="display:none">
                <label class="layui-form-label" style="display:none">升降序：</label>
                <div class="layui-input-inline layui-inline-2">
                    <select name="thesort" id="thesort">
                        <option value="desc">降序</option>
                        <option value="asc">升序</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline" style="display:none">
                <label class="layui-form-label">排名条件：</label>
                <div class="layui-input-inline layui-inline-2">
                    <select name="filter" id="filter">
                        <option value="nums">销量</option>
                        <option value="amount">销售额</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <button class="layui-btn layui-btn-sm" lay-submit lay-filter="LAY-app-Goods-search"><i class="layui-icon layui-icon-search"></i>筛选</button>
                <button class="layui-btn layui-btn-primary layui-btn-sm" val="1" lay-submit lay-filter="goodCheck">今日</button>
                <button class="layui-btn layui-btn-primary layui-btn-sm" val="2" lay-submit lay-filter="goodCheck">昨日</button>
                <button class="layui-btn layui-btn-primary layui-btn-sm" val="3" lay-submit lay-filter="goodCheck">本周</button>
                <button class="layui-btn layui-btn-primary layui-btn-sm" val="4" lay-submit lay-filter="goodCheck">上周</button>
                <button class="layui-btn layui-btn-primary layui-btn-sm" val="5" lay-submit lay-filter="goodCheck">本月</button>
                <button class="layui-btn layui-btn-primary layui-btn-sm" val="6" lay-submit lay-filter="goodCheck">上月</button>
                <button class="layui-btn layui-btn-primary layui-btn-sm" val="7" lay-submit lay-filter="goodCheck">7日内</button>
                <button class="layui-btn layui-btn-primary layui-btn-sm" val="8" lay-submit lay-filter="goodCheck">一月内</button>
                <button class="layui-btn layui-btn-primary layui-btn-sm" val="9" lay-submit lay-filter="goodCheck">三月内</button>
                <button class="layui-btn layui-btn-primary layui-btn-sm" val="10" lay-submit lay-filter="goodCheck">半年内</button>
                <button class="layui-btn layui-btn-primary layui-btn-sm" val="11" lay-submit lay-filter="goodCheck">一年内</button>
                <button class="layui-btn layui-btn-primary layui-btn-sm" val="12" lay-submit lay-filter="goodCheck">本年度</button>
                <button class="layui-btn layui-btn-primary layui-btn-sm" val="13" lay-submit lay-filter="goodCheck">上年度</button>
            </div>
        </div>
        <div class="layui-form-item">

           </div>
        </div>
</script>

<div class="table-body">
    <table id="LAY-app-Report-Goods-tableBox" lay-filter="LAY-app-Report-Goods-tableBox"></table>
</div>


<script type="text/html" id="LAY-app-Report-toolbar">
    <div class="report_table_bar"><span><i class="layui-icon layui-icon-triangle-r"></i> 右侧按钮进行打印下载操作。</span></div>
</script>

<script type="text/javascript">
    var debug = layui.setter.debug;
    layui.use(['index', 'element', 'laydate', 'form', 'table', 'coreHelper', 'util', 'table'], function () {
        var $ = layui.$;
        var form = layui.form;
        var element = layui.element;
        var coreHelper = layui.coreHelper;
        var setter = layui.setter;
        var util = layui.util;
        var table = layui.table;
        var tableData = {};


        var searchwhere;
        //监听搜索
        form.on('submit(LAY-app-Goods-search)',
            function (data) {
                var field = data.field;
                searchwhere = field;
                //执行重载
                table.reloadData('LAY-app-Report-Goods-tableBox', { where: field, page: { curr: 1 } });
            });

        //第一个实例
        table.render({
            elem: '#LAY-app-Report-Goods-tableBox', //指定原始表格元素选择器（推荐id选择器）
            method: 'POST',
            toolbar: '#LAY-app-Report-toolbar',
            defaultToolbar: ['filter', 'print', 'exports'],
            height: 'full-132',//面包屑142px,搜索框4行172,3行137,2行102,1行67
            //cellMinWidth: '80',
            toolbar: '#LAY-app-Goods-toolbar',
            //id: 'LAY-app-Report-Goods-tableBox',
            url: "Api/CoreCmsReports/GetReportOrder",
            page: 'true',
            limit: '20',
            cols: [[ //表头
                { field: 'companyName', title: '公司名称', align: 'center', width: 80 },
                { field: 'depName', title: '部门', align: 'center', width: 80 },
                { field: 'groupName', title: '组别', align: 'center', width: 80 },
                { field: 'nickName', title: '姓名', align: 'center', width: 80 },
                { field: 'val', title: '下单金额', align: 'center', width: 80 },
                { field: 'num', title: '下单数量', align: 'center', width: 80 },
                { field: 'sendAmount', title: '发货金额', align: 'center', width: 80 },
                { field: 'sendCount', title: '发货数量', align: 'center', width: 80 },
                { field: 'signedAmount', title: '签收金额', align: 'center', width: 80 },
                { field: 'signedCount', title: '签收数量', align: 'center', width: 80 },
                { field: 'completeAmount', title: '完成金额', align: 'center', width: 80 },
                { field: 'completeCount', title: '完成数量', align: 'center', width: 80 },
                { field: 'refundAmount', title: '退货金额', align: 'center', width: 80 },
                { field: 'refundCount', title: '退货数量', align: 'center', width: 80 },
                //{ field: 'index', title: '排名', type: 'numbers', width: 60 },
                //{ field: 'nums', title: '销量', align: 'center', width: 60 },
                //{ field: 'amount', title: '销售额', align: 'center', width: 80 },
                //{
                //    field: 'imageUrl', width: 60, title: '缩略图', align: 'center', templet: function (data) {
                //        if (data.imageUrl && data.imageUrl != 'null') {
                //            return '<a href="javascript:void(0);" onclick=layui.coreHelper.viewImage("' + data.imageUrl + '")><image style="max-width:28px;max-height:28px;" src="' + data.imageUrl + '" /></a>';
                //        } else {
                //            return '<a href="javascript:void(0);" onclick=layui.coreHelper.viewImage("' + setter.noImagePicUrl + '")><image style="max-width:30px;max-height:30px;" src="' + setter.noImagePicUrl + '" /></a>';
                //        }
                //    }
                //},
                //{ field: 'name', title: '商品名称', align: 'center' },
                //{ field: 'addon', title: '规格', align: 'center', width: 250 },
                //{ field: 'sn', title: '货号', width: 150 }
            ]]
        });

        layui.form.on('submit(goodCheck)', function (data) {
            type = data.elem.getAttribute('val');
            console.log('type', type);
            if (type != "") {
                getTime(type, function (date) {
                    if (date) {
                        data.field.date = date;
                    }
                    table.reloadData('LAY-app-Report-Goods-tableBox', {
                        where: data.field
                        , page: {
                            curr: 1 //重新从第 1 页开始
                        }
                    });
                });
            } else {
                table.reloadData('table', {
                    where: data.field
                    , page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
            }
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        //重载form
        form.render();

        //解析时间按钮
        function getTime(type, calback) {
            var data = {
                id: type
            };
            coreHelper.Post("Api/CoreCmsReports/GetDateType", data, function (res) {
                if (debug) { console.log(res); } //开启调试返回数据
                if (res.code == 0) {
                    //设置时间，回调
                    $('#date').val(res.data.start + " 到 " + res.data.end);
                    calback($('#date').val());
                } else {
                    layer.msg(res.msg);
                }
            });
        }

        //时间插件
        var date = new Date();
        layui.laydate.render({
            elem: '#date',
            range: '到',
            type: 'date',
            value: util.toDateString(date, 'yyyy-MM-dd') + ' 到 ' + util.toDateString(date, 'yyyy-MM-dd'),
            trigger: 'click'
        });


    });
</script>